package com.fenjiangfan.growth.system.common.exception;

import com.fenjiangfan.growth.system.common.errorcode.IErrorCode;
import lombok.Getter;
import org.springframework.util.StringUtils;

import java.util.Optional;

/**
 * 定义基础异常
 */
@Getter
public abstract class AbsractException extends RuntimeException {

    public final String errorCode;

    public final String errorMessage;

    public AbsractException(IErrorCode errorCode, String errorMessage, Throwable throwable) {
        super(errorMessage,throwable);
        this.errorCode = errorCode.code();
        this.errorMessage = Optional.ofNullable(StringUtils.hasLength(errorMessage) ? errorMessage : null).orElse(errorCode.message());
    }
}
